import { Injectable, Injector } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from '../../../../../environments/environment';
import { RyBaseServiceService } from '../../../../common/RyBaseService.service';
import {map} from "rxjs/operators";

@Injectable({
    providedIn: 'root'
})
export class UserService extends RyBaseServiceService{
    base = '/system/user';
    constructor(private _injector: Injector,) {
        super(_injector);
        super.setBase(this.base);
    }

    deptTree(): Observable<any> {
        const options = {
        };
        return this._http.get<any[]>(environment.baseUrl + this.base + '/deptTree', options);
    }

    /**
     * 获取个人资料
     */
    getProfile(): Observable<any> {
        return this._http.get<any>(environment.baseUrl + this.base + '/profile',{});
    }

    /**
     * 获取个人资料
     */
    saveProfile(data:any): Observable<any> {
        return this._http.put<any>(environment.baseUrl + this.base + '/profile',data);
    }

    updatePwd(data:any): Observable<any> {
        const options = {
            params: data
        };
        return this._http.put<any>(environment.baseUrl + this.base + '/profile/updatePwd',{},options);
    }

    resetPwd(data:any): Observable<any> {
        return this._http.put<any>(environment.baseUrl + this.base + '/resetPwd',data);
    }

    getAuthUser(userId: string) {
         return this._http.get<any>(environment.baseUrl + this.base + '/authRole/'+userId,{});
    }
    authUser(userId: string, roles:string) {
        const options = {
            params: {
                userId,
                roles
            }
        };
         return this._http.put<any>(environment.baseUrl + this.base + '/authRole',{},options);
    }

    /**
     * 获取用户信息
     */
    getUserResume(): Observable<any> {
        return this._http.get(environment.baseUrl + this.base + '/getInfo').pipe( map((res: any) => {
            return res;
        }));
    }
}
